package com.ikas.ai.server.module.morningpaper.model.elements.condition;

import com.alibaba.fastjson.JSON;
import com.ikas.ai.server.module.data.model.BaseMete;
import com.ikas.ai.server.module.data.model.tdengine.RealDataHis;
import com.ikas.ai.server.module.morningpaper.model.elements.AbstractElementNeedsTDEngine;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.Map;

@Slf4j
public abstract class AbstractElementMachineConditionCount extends AbstractElementNeedsTDEngine {
    protected Long fillConditionCount(AbstractElementMachineConditionCount element, Map<String, Object> transmitMap) {
        Long meteId = getMeteId(element);
        log.info("该早报变量meteId:{}", meteId);
        List<RealDataHis> meteHis = getMeteHis(meteId);
        log.info("该测点对应td数据:{}", JSON.toJSONString(meteHis));
        transmitMap.put(element.getMorningPaperVariableName(), meteHis);
        if (meteHis.size() == 0) return 0L;
        BaseMete U01conditionGBaseMete = getBaseMeteYxCache(getMeteId(element));
        Integer validMeteValue = U01conditionGBaseMete.getValidMeteValue();
        return meteHis.stream().filter(mete -> validMeteValue.equals(Integer.valueOf(mete.getValue()))).count();
    }

}
